#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Premiere.Window;
using Premiere.DTO;
using Premiere.Framework;
using System.Collections;

#endregion

namespace PremiereMX
{
    public partial class UserControlGeneralSetUp : UserControl, IUserControlGeneralSetUp
    {
        GeneralSetUpLogic m_logic;
        IMainForm m_mainForm;
        bool m_init = false;

        public UserControlGeneralSetUp(string name, IMainForm mainForm)
        {
            InitializeComponent();
            m_logic = new GeneralSetUpLogic(mainForm, this);
            toolBarButtonEdit.Click += new EventHandler(toolBarButtonEdit_Click);
            toolBarButtonSave.Click += new EventHandler(toolBarButtonSave_Click);
            m_mainForm = mainForm;
            this.Name = name;
        }
        void toolBarButtonSave_Click(object sender, EventArgs e)
        {
            m_logic.Save();
        }
        void toolBarButtonEdit_Click(object sender, EventArgs e)
        {
            m_logic.Edit();
        }
        public void SetButtonEditMode(EditMode editMode)
        {
            this.toolBarButtonSave.Enabled = ((editMode.Equals(EditMode.Edit) || editMode.Equals(EditMode.Insert))) && m_mainForm.GetRules(this.Name).Edit;
            this.toolBarButtonEdit.Enabled = ((editMode.Equals(EditMode.OK))) && m_mainForm.GetRules(this.Name).Edit;
        }
        public void SetToReadOnly(bool p)
        {
            bool value = !p;
            companyNametextBox.Enabled = value;
            companyAddresstextBox.Enabled = value;
            companyCitytextBox.Enabled = value;
            companyPhonetextBox.Enabled = value;
            companyfaxtextBox.Enabled = value;
            companyTaxNotextBox.Enabled = value;
            companyRegDatedateTimePicker.Enabled = value;
            companyemailtextBox.Enabled = value;
            companyhomePagetextBox.Enabled = value;
            allowMinusStockcheckBox.Enabled = value;
            minusStockWarningcheckBox.Enabled = value;
            changePricecheckBox.Enabled = value;
            duplicatePartWarningcheckBox4.Enabled = value;
            partCurrencyControlcheckBox.Enabled = value;
            multiDivisioncheckBox.Enabled = value;
            multiWarehousecheckBox.Enabled = value;
            baseCurrencycomboBox.Enabled = value;
            costingMethodcomboBox.Enabled = value;
            partViewNameComboBox.Enabled = value;
            vendorViewNameComboBox.Enabled = value;
            salesdiscountpercentpartcheckBox.Enabled = value;
            salesdiscountamountbypartcheckBox.Enabled = value;
            salesbonuscheckBox.Enabled = value;
            salesdiscountpercentbytotalcheckBox.Enabled = value;
            salesdiscountamountbytotalcheckBox.Enabled = value;
            salesotheramountcheckBox.Enabled = value;
            salestaxcheckBox.Enabled = value;
            purchasediscountpercentbypartcheckBox.Enabled = value;
            purchasediscountamountbypartcheckBox.Enabled = value;
            purchasebonuscheckBox.Enabled = value;
            purchasediscountpercentbytotalcheckBox.Enabled = value;
            purchasediscountamountbytotalcheckBox.Enabled = value;
            purchaseotheramountcheckBox.Enabled = value;
            purchasetaxcheckBox.Enabled = value;
            exchagerateccycomboBox.Enabled = value;
            haveChashierInTransactioncheckBox.Enabled = value;
            partCategorycheckBox.Enabled = value;
            partCategory1checkBox.Enabled = value;
            partcategory2checkBox.Enabled = value;
            partCategory3checkBox.Enabled = value;
            colnamepc1textBox.Enabled = value;
            colnamepc2textBox.Enabled = value;
            colnamepc3textBox.Enabled = value;
            customercategorycheckBox.Enabled = value;
            customercategory1checkBox.Enabled = value;
            customercategory2checkBox.Enabled = value;
            customercategory3checkBox.Enabled = value;
            colnamecc1textBox.Enabled = value;
            colnamecc2textBox.Enabled = value;
            colnamecc3textBox.Enabled = value;
            suppliercategorycheckBox.Enabled = value;
            suppliercategory1checkBox.Enabled = value;
            suppliercategory2checkBox.Enabled = value;
            suppliercategory3checkBox.Enabled = value;
            colnamesc1textBox.Enabled = value;
            colnamesc2textBox.Enabled = value;
            colnamesc3textBox.Enabled = value;
            //gridAutonumber.Enabled = value;
            bool istheretransaction = m_logic.GetStockCardEntryCount();//ServiceRegistry.GetInstance().GetPeriodService().GetStockCardEntryCount() > 0;
            startEntryPeriodcomboBox.Enabled = value && !istheretransaction;
            Prefix.ReadOnly = !value;
            Start.ReadOnly = !value;
            Digit.ReadOnly = !value;
            Initial.ReadOnly = !value;
            Type.ReadOnly = !value;
        }
        public void ShowMessage(string mess)
        {
            MessageBox.Show(mess, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void ConstructAutoNumberGridColumn()
        {

        }
       // int rw = 0;
        public void AddAutoNumberSetup(AutoNumberSetupDTO dto)
        {
           // dataGridViewAutonumber.RowCount++;
            //int row = dataGridViewAutonumber.RowCount;
            //dataGridViewAutonumber[0, row - 1] = new DataGridViewTextBoxCell();
            //dataGridViewAutonumber[1, row - 1] =new DataGridViewTextBoxCell();
            //dataGridViewAutonumber[2, row - 1] = new DataGridViewTextBoxCell();
            //dataGridViewAutonumber[3, row - 1] = new DataGridViewTextBoxCell();
            //dataGridViewAutonumber[4, row - 1] = new DataGridViewComboBoxCell();
            //dataGridViewAutonumber[5, row - 1] = new DataGridViewComboBoxCell();

            //dataGridViewAutonumber[0, rw].Value = dto.FormName;
            //dataGridViewAutonumber[1, rw].Value = dto.Prefix;
            //dataGridViewAutonumber[2, rw].Value = dto.Start;
            //dataGridViewAutonumber[3, rw].Value = dto.Digit;
            //dataGridViewAutonumber[4, rw].Value = dto.InitialAutoNumberSetup;
            //dataGridViewAutonumber[5, rw].Value = dto.AutoNumberSetupType;
            //rw++;
            DataGridViewRow rw = dataGridViewAutonumber.Rows[dataGridViewAutonumber.Rows.Add(dto.FormName, dto.Prefix, dto.Start.ToString(), dto.Digit.ToString(), dto.InitialAutoNumberSetup.ToString(), dto.AutoNumberSetupType.ToString())];
            rw.Tag = dto;
        }
        
        #region IUserControlGeneralSetUp Members

        public void UpdateButton()
        {
             m_mainForm.UpdateButton(toolBarMain.Buttons);
        }
        public void SetMainForm(IMainForm mainform)
        {
            m_mainForm = mainform;
        }
        public string CompName
        {
            get
            {
                return companyNametextBox.Text;
            }
            set
            {
                companyNametextBox.Text = value;
            }
        }
        public string CompanyAddress
        {
            get
            {
                return companyAddresstextBox.Text;
            }
            set
            {
                companyAddresstextBox.Text = value;
            }
        }
        public string CompanyCity
        {
            get
            {
                return companyCitytextBox.Text;
            }
            set
            {
                companyCitytextBox.Text = value;
            }
        }
        public string CompanyPhone
        {
            get
            {
                return companyPhonetextBox.Text;
            }
            set
            {
                companyPhonetextBox.Text = value;
            }
        }
        public string CompanyFax
        {
            get
            {
                return companyfaxtextBox.Text;
            }
            set
            {
                companyfaxtextBox.Text = value;
            }
        }
        public string CompanyTax
        {
            get
            {
                return companyTaxNotextBox.Text;
            }
            set
            {
                companyTaxNotextBox.Text = value;
            }
        }
        public DateTime CompanyRegDate
        {
            get
            {
                return companyRegDatedateTimePicker.Value;
            }
            set
            {
                companyRegDatedateTimePicker.Value = value;
            }
        }
        public string CompanyEmail
        {
            get
            {
                return companyemailtextBox.Text;
            }
            set
            {
                companyemailtextBox.Text = value;
            }
        }
        public string CompanyWebsite
        {
            get
            {
                return companyhomePagetextBox.Text;
            }
            set
            {
                companyhomePagetextBox.Text = value;
            }
        }
        public bool AllowMinus
        {
            get
            {
                return allowMinusStockcheckBox.Checked;
            }
            set
            {
                allowMinusStockcheckBox.Checked = value;
            }
        }
        public bool MinusStockWarning
        {
            get
            {
                return minusStockWarningcheckBox.Checked;
            }
            set
            {
                minusStockWarningcheckBox.Checked = value;
            }
        }
        public bool ChangeLatestPurchasePrice
        {
            get
            {
                return changePricecheckBox.Checked;
            }
            set
            {
                changePricecheckBox.Checked = value;
            }
        }
        public bool DuplicatePartWarning
        {
            get
            {
                return duplicatePartWarningcheckBox4.Checked;
            }
            set
            {
                duplicatePartWarningcheckBox4.Checked = value;
            }
        }
        public bool PartCurrencyControl
        {
            get
            {
                return partCurrencyControlcheckBox.Checked;
            }
            set
            {
                partCurrencyControlcheckBox.Checked = value;
            }
        }
        public bool MultiDivision
        {
            get
            {
                return multiDivisioncheckBox.Checked;
            }
            set
            {
                multiDivisioncheckBox.Checked = value;
            }
        }
        public bool MultiWarehouse
        {
            get
            {
                return multiWarehousecheckBox.Checked;
            }
            set
            {
                multiWarehousecheckBox.Checked = value;
            }
        }
        public CurrencyDTO BaseCurrency
        {
            get
            {
                return baseCurrencycomboBox.SelectedItem as CurrencyDTO;
            }
            set
            {
                baseCurrencycomboBox.Text = value == null ? string.Empty : value.ToString();
            }
        }
        public CostMethod CostMethod
        {
            get
            {
                return (CostMethod)costingMethodcomboBox.SelectedItem;
            }
            set
            {
                costingMethodcomboBox.SelectedItem = value;
            }
        }
        public DTOToString PartToString
        {
            get
            {
                return (DTOToString)partViewNameComboBox.SelectedItem;
            }
            set
            {
                partViewNameComboBox.SelectedItem = value;
            }
        }
        public DTOToString CustomerToString
        {
            get
            {
                return (DTOToString)vendorViewNameComboBox.SelectedItem;
            }
            set
            {
                vendorViewNameComboBox.SelectedItem = value;
            }
        }
        public bool SalesDiscountPercentByPart
        {
            get
            {
                return salesdiscountpercentpartcheckBox.Checked;
            }
            set
            {
                salesdiscountpercentpartcheckBox.Checked = value;
            }
        }
        public bool SalesDiscountAmountByPart
        {
            get
            {
                return salesdiscountamountbypartcheckBox.Checked;
            }
            set
            {
                salesdiscountamountbypartcheckBox.Checked = value;
            }
        }
        public bool SalesBonus
        {
            get
            {
                return salesbonuscheckBox.Checked;
            }
            set
            {
                salesbonuscheckBox.Checked = value;
            }
        }
        public bool SalesDiscountPercentByTotal
        {
            get
            {
                return salesdiscountpercentbytotalcheckBox.Checked;
            }
            set
            {
                salesdiscountpercentbytotalcheckBox.Checked = value;
            }
        }
        public bool SalesDiscountAmountByTotal
        {
            get
            {
                return salesdiscountamountbytotalcheckBox.Checked;
            }
            set
            {
                salesdiscountamountbytotalcheckBox.Checked = value;
            }
        }
        public bool SalesOtherAmount
        {
            get
            {
                return salesotheramountcheckBox.Checked;
            }
            set
            {
                salesotheramountcheckBox.Checked = value;
            }
        }
        public bool SalesTax
        {
            get
            {
                return salestaxcheckBox.Checked;
            }
            set
            {
                salestaxcheckBox.Checked = value;
            }
        }
        public bool PurchaseDiscountPercentByPart
        {
            get
            {
                return purchasediscountpercentbypartcheckBox.Checked;
            }
            set
            {
                purchasediscountpercentbypartcheckBox.Checked = value;
            }
        }
        public bool PurchaseDiscountAmountByPart
        {
            get
            {
                return purchasediscountamountbypartcheckBox.Checked;
            }
            set
            {
                purchasediscountamountbypartcheckBox.Checked = value;
            }
        }
        public bool PurchaseBonus
        {
            get
            {
                return purchasebonuscheckBox.Checked;
            }
            set
            {
                purchasebonuscheckBox.Checked = value;
            }
        }
        public bool PurchaseDiscountPercentByTotal
        {
            get
            {
                return purchasediscountpercentbytotalcheckBox.Checked;
            }
            set
            {
                purchasediscountpercentbytotalcheckBox.Checked = value;
            }
        }
        public bool PurchaseDiscountAmountByTotal
        {
            get
            {
                return purchasediscountamountbytotalcheckBox.Checked;
            }
            set
            {
                purchasediscountamountbytotalcheckBox.Checked = value;
            }
        }
        public bool PurchaseOtherAmount
        {
            get
            {
                return purchaseotheramountcheckBox.Checked;
            }
            set
            {
                purchaseotheramountcheckBox.Checked = value;
            }
        }
        public bool PurchaseTax
        {
            get
            {
                return purchasetaxcheckBox.Checked;
            }
            set
            {
                purchasetaxcheckBox.Checked = value;
            }
        }
        public CurrencyDTO ExchangeRateCurrency
        {
            get
            {
                return exchagerateccycomboBox.SelectedItem as CurrencyDTO;
            }
            set
            {
                exchagerateccycomboBox.Text = value == null ? string.Empty : value.ToString();
            }
        }
        public bool HaveCashierInTransaction
        {
            get
            {
                return haveChashierInTransactioncheckBox.Checked;
            }
            set
            {
                haveChashierInTransactioncheckBox.Checked = value;
            }
        }
        public bool PartCategory
        {
            get
            {
                return partCategorycheckBox.Checked;
            }
            set
            {
                partCategorycheckBox.Checked = value;
            }
        }
        public bool PartCategory1
        {
            get
            {
                return partCategory1checkBox.Checked;
            }
            set
            {
                partCategory1checkBox.Checked = value;
            }
        }
        public bool PartCategory2
        {
            get
            {
                return partcategory2checkBox.Checked;
            }
            set
            {
                partcategory2checkBox.Checked = value;
            }
        }
        public bool PartCategory3
        {
            get
            {
                return partCategory3checkBox.Checked;
            }
            set
            {
                partCategory3checkBox.Checked = value;
            }
        }
        public string PartCategory1ColumnName
        {
            get
            {
                return colnamepc1textBox.Text;
            }
            set
            {
                colnamepc1textBox.Text = value;
            }
        }
        public string PartCategory2ColumnName
        {
            get
            {
                return colnamepc2textBox.Text;
            }
            set
            {
                colnamepc2textBox.Text = value;
            }
        }
        public string PartCategory3ColumnName
        {
            get
            {
                return colnamepc3textBox.Text;
            }
            set
            {
                colnamepc3textBox.Text = value;
            }
        }
        public bool CustomerCategory
        {
            get
            {
                return customercategorycheckBox.Checked;
            }
            set
            {
                customercategorycheckBox.Checked = value;
            }
        }
        public bool CustomerCategory1
        {
            get
            {
                return customercategory1checkBox.Checked;
            }
            set
            {
                customercategory1checkBox.Checked = value;
            }
        }
        public bool CustomerCategory2
        {
            get
            {
                return customercategory2checkBox.Checked;
            }
            set
            {
                customercategory2checkBox.Checked = value;
            }
        }
        public bool CustomerCategory3
        {
            get
            {
                return customercategory3checkBox.Checked;
            }
            set
            {
                customercategory3checkBox.Checked = value;
            }
        }
        public string CustomerCategory1ColumnName
        {
            get
            {
                return colnamecc1textBox.Text;
            }
            set
            {
                colnamecc1textBox.Text = value;
            }
        }
        public string CustomerCategory2ColumnName
        {
            get
            {
                return colnamecc2textBox.Text;
            }
            set
            {
                colnamecc2textBox.Text = value;
            }
        }
        public string CustomerCategory3ColumnName
        {
            get
            {
                return colnamecc3textBox.Text;
            }
            set
            {
                colnamecc3textBox.Text = value;
            }
        }
        public bool SupplierCategory
        {
            get
            {
                return suppliercategorycheckBox.Checked;
            }
            set
            {
                suppliercategorycheckBox.Checked = value;
            }
        }
        public bool SupplierCategory1
        {
            get
            {
                return suppliercategory1checkBox.Checked;
            }
            set
            {
                suppliercategory1checkBox.Checked = value;
            }
        }
        public bool SupplierCategory2
        {
            get
            {
                return suppliercategory2checkBox.Checked;
            }
            set
            {
                suppliercategory2checkBox.Checked = value;
            }
        }
        public bool SupplierCategory3
        {
            get
            {
                return suppliercategory3checkBox.Checked;
            }
            set
            {
                suppliercategory3checkBox.Checked = value;
            }
        }
        public string SupplierCategory1ColumnName
        {
            get
            {
                return colnamesc1textBox.Text;
            }
            set
            {
                colnamesc1textBox.Text = value;
            }
        }
        public string SupplierCategory2ColumnName
        {
            get
            {
                return colnamesc2textBox.Text;
            }
            set
            {
                colnamesc2textBox.Text = value;
            }
        }
        public string SupplierCategory3ColumnName
        {
            get
            {
                return colnamesc3textBox.Text;
            }
            set
            {
                colnamesc3textBox.Text = value;
            }
        }
        public PeriodDTO StartEntryPeriod
        {
            get
            {
                return startEntryPeriodcomboBox.SelectedItem as PeriodDTO;
            }
            set
            {
                startEntryPeriodcomboBox.Text = value == null ? string.Empty : value.ToString();
            }
        }
        public string ComputerName
        {
            set {}// this.computerNametoolStripStatusLabel5.Text = "[" + value + "]"; }
        }
        public DateTime LastUpdate
        {
            set {}// lastUpdatetoolStripStatusLabel.Text = value.ToString("dd-MMM-yyyy, hh:mm:ss"); }
        }
        public string UserName
        {
            set
            {
                //throw new NotImplementedException();
            }
        }
        public void Init()
        {
            if (m_init) return;
            m_init = true;
            m_logic.Init();
            costingMethodcomboBox.DataSource = Enum.GetValues(typeof(CostMethod));
            partViewNameComboBox.DataSource = Enum.GetValues(typeof(DTOToString));
            vendorViewNameComboBox.DataSource = Enum.GetValues(typeof(DTOToString));
            exchagerateccycomboBox.DataSource = m_logic.GetCurrencyList();
            baseCurrencycomboBox.DataSource = m_logic.GetCurrencyList();
            startEntryPeriodcomboBox.DataSource = m_logic.GetPeriodList();
            Initial.Items.AddRange(Enum.GetNames(typeof(InitialAutoNumberSetup)));
            Type.Items.AddRange(Enum.GetNames(typeof(AutoNumberSetupType)));
            //dataGridViewAutonumber.RowCount = 30;
        }
        public void Refresh()
        {
            m_init = false;
            Init();
            m_logic.Refresh();
        }
        public IList UpdateAutoNumberItems()
        {
            IList list = new ArrayList();
            foreach (DataGridViewRow rw in dataGridViewAutonumber.Rows)
            {
                if (rw.Tag == null) continue;
                AutoNumberSetupDTO auto = (AutoNumberSetupDTO)rw.Tag;
                auto.Prefix = dataGridViewAutonumber[1, rw.Index].Value.ToString();
                auto.Start = Convert.ToInt16(dataGridViewAutonumber[2, rw.Index].Value);
                auto.Digit = Convert.ToInt16(dataGridViewAutonumber[3, rw.Index].Value);
                auto.InitialAutoNumberSetup = (InitialAutoNumberSetup)Enum.Parse(typeof(InitialAutoNumberSetup), dataGridViewAutonumber[4, rw.Index].Value.ToString());
                auto.AutoNumberSetupType = (AutoNumberSetupType)Enum.Parse(typeof(AutoNumberSetupType), dataGridViewAutonumber[5, rw.Index].Value.ToString());
                list.Add(auto);
            }
            return list;
        }
        public void ClearForm()
        {

        }

        public void RemoveItem(long id)
        {
            throw new NotImplementedException();
        }

        public void FocusToCode()
        {
            
        }

        public bool IsValidSubject()
        {
            //errorProvider1.SetError(textBoxCode, "");
            //errorProvider1.SetError(textBoxName, "");
            //bool a = textBoxCode.Text == string.Empty;
            //bool b = textBoxName.Text == string.Empty;
            //if (a) errorProvider1.SetError(textBoxCode, "Please fill Code");
            //if (a) errorProvider1.SetError(textBoxName, "Please fill Name");
            return true;
        }

        #endregion
    }
}